<?php

namespace app\index\controller\tan;
class ReturnData{
    static public function err($code,$data=[],$msg=""){
        echo json_encode([
            "code"=>$code,
            "msg"=> "错误  ". $msg,
            "data"=>$data
        ]);
        die;
    }
    static public function ok($data=[]){
        echo json_encode([
            "code"=>666,
            "msg"=> "正常",
            "data"=>$data
        ]);
        die;
    }
    static public function ifState($code,$data){
        if(empty($data)){
             self::err($code);
        } else {
            self::ok($data);
        }
    }
    /**
     * 如果不恒等与true，则错误并停止执行<b>date不为true时就是string类型</b>
     * @param type $data    bool 或string
     * @param type $code    编码
     */
    static public function IfTrue($data,$code){
        if($data !== true){
            self::err($code,[],$data);
        }
    }

    static public function bo($bool,$code,$data=[],$msg=""){
        if($bool){
//            self::ok();
        }else{
            self::err($code,$data,$msg);
        }
    }
    /**
     * 判断是否为真，真就返回ok
     * @param type $bool
     * @param type $code
     * @param type $data
     * @param type $msg
     */
    static public function exit_($bool,$code,$data=[],$msg=""){
        if($bool){
            self::ok();
        }else{
            self::err($code,$data,$msg);
        }
    }
}
